import sys
sys.path.append("../")

from controller.ScoreCalcController import *
from services.CodesService import *
from frameworks.utils.PrettyTableUtil import *
from frameworks.cores.LoadClass import *
from frameworks.utils.MyThread import *
from services.DayKlineService import *
from queue import Queue
#queue = Queue(5000)

startDay = "2024-12-01"
endDay = "2025-01-23"
resultDay = "2025-01-24"
#codeService = CodeService()
#codes = codeService.getAllCodes()
#con = ScoreCalcController()

load = LoadClass()

#pretty = PrettyTableUtil(["证券代码", "证券名称", "行业", "流通市值", "score", "涨幅"])

def callday(startDay,endDay,resultDay):
    threads = []
    data = []
    max_connections = 5  # 定义最大线程数
    pool_sema = threading.BoundedSemaphore(max_connections)  # 或使用Semaphore方法
    for i in range(0, 10):
        args = {}
        args["id"] = i
        args["pretty"] = data
        args["startDay"] = startDay
        args["endDay"] = endDay
    #    args["queue"] = queue
        args["resultDay"] = resultDay
        thread1 = MyThread(i+1, "controller", "ParseScoreStockController", args)
        thread1.start()
        threads.append(thread1)
    for t in threads:
        t.join()
"""
while queue.empty() == False:
    lastcode = queue.get()
    pretty.addRow(lastcode)
    # 线程等待和线程同步
    queue.task_done()
print(pretty.renderTable("score"))
"""
if __name__ == "__main__":
    con = DayKlineService()
    allday = con.getTradeDay()
    print(allday)
    max = len(allday) -1
    for i in range(len(allday)):
        if i + 11 > max:
            break
        m = i + 10
        n = i + 11
        if n > len(allday):
            break
        print(allday[i],allday[m],allday[n])
        callday(allday[i],allday[m],allday[n])
        i += 1
